package com.itheima.ydd.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.ydd.common.R;
import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.dto.Dto.YddAllDte;
import com.itheima.ydd.entity.*;
import com.itheima.ydd.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.image.Kernel;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
@Slf4j
public class IIndexServiceImpl implements IIndexService {
    @Autowired
    private IYddCateService iYddCateService;
    @Autowired
    private IYddTagService iYddTagService;
    @Autowired
    private IYddLinkService iYddLinkService;
    @Autowired
    private IYddAdvimgService iYddAdvimgService;
    @Autowired
    private ISysConfigService iSysConfigService;
    @Override
    public R baseInfo(Long userId) {
        return null;
    }

    @Override
    public ResultData index() {
        YddAllDte yddAllDte=new YddAllDte();
        //allCate所有分类
        List<YddCate> yddCateList = iYddCateService.list();
        yddAllDte.setAllCate(yddCateList);
        //config配置数据



        //allTag所有标签
        List<YddTag> yddTagList = iYddTagService.list();
        yddAllDte.setAllTag(yddTagList);
        //allLink所有友情链接
        List<YddLink> yddLinkList = iYddLinkService.list();
        yddAllDte.setAllLink(yddLinkList);
        //banner轮播图数据
        Integer bannerId=15;
        List<YddAdvimg> bannerTu1 = iYddAdvimgService.getTu(bannerId);
        Map<Object,Object>map=new HashMap<>();
        ArrayList<Object> list = new ArrayList<>();

        for (YddAdvimg yddAdvimg : bannerTu1) {
            Map<Object,Object>map1=new HashMap<>();
            map1.put("yddAdvimg",yddAdvimg.getId());
            map1.put("advimglink",yddAdvimg.getAdvimglink());
            map1.put("advimgdesc", yddAdvimg.getAdvimgdesc());
            map1.put("advimgsrc", yddAdvimg.getAdvimgsrc());
            list.add(map1);
//            map1 = null;
        }

//        bannerTu1.stream().map(item->{
//            map1.put("item",item.getId());
//            map1.put("advimglink",item.getAdvimglink());
//            map1.put("advimgdesc", item.getAdvimgdesc());
//            map1.put("advimgsrc", item.getAdvimgsrc());
////            map.put(i, map1);
//            list.add(map1);
//            return item;
//        }).collect(Collectors.toList());
        yddAllDte.setBanner(map);
        //sideBanner侧边栏图片
        Integer sideId= 14;
        List<YddAdvimg> bannerTu2 = iYddAdvimgService.getTu(sideId);
        YddAdvpos bannerAdvpos=new YddAdvpos();
        List list1 = new ArrayList<>();
        Map<Object,Object>mapS=new HashMap<>();
        Map<Object,Object>maps=new HashMap<>();
        bannerTu2.stream().map((item)->{
            maps.put("id",item.getId());
            maps.put("advimglink",item.getAdvimglink());
            maps.put("advimgdesc", item.getAdvimgdesc());
            maps.put("advimgsrc", item.getAdvimgsrc());
            list1.add(maps);
//            mapS.put("sideBanner", maps);
            return item;
        }).collect(Collectors.toList());
        yddAllDte.setSideBanner(mapS);
        //showBanner详情广告图
        Integer showId=13;
        List<YddAdvimg> bannerTu3 = iYddAdvimgService.getTu(showId);
        Map<Object,Object>mapH=new HashMap<>();
        Map<Object,Object>maph=new HashMap<>();
        bannerTu3.stream().map((item)->{
            maph.put("id",item.getId());
            maph.put("advimglink",item.getAdvimglink());
            maph.put("advimgdesc", item.getAdvimgdesc());
            maph.put("advimgsrc", item.getAdvimgsrc());
            mapH.put("sideBanner", maph);
            return item;
        }).collect(Collectors.toList());
        yddAllDte.setShowBanner(mapH);
        return ResultData.ok("", yddAllDte);
    }
}
